<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 很重要的 accept文件类型的设置 -->
    <input type="file" multiple accept="image/png,image/jpg" />
    <!-- <input type="file" multiple accept="image/*"> -->
    <img src="" alt="" />

    <script>
      const ipt = document.querySelector('input')
      ipt.addEventListener('change', function () {
        console.log(ipt.files) //伪数组,原生dom上的方法
        const img = URL.createObjectURL(ipt.files[0]) // 转化伪地址
        document.querySelector('img').src = img
      })
    </script>
  </body>
</html>
